﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TestCenter.Delegate
{
	public class Delegate : TestBase
	{
		public override void Test()
		{
			test1();
		}

		public void test1()
		{
			List<string> names = new List<string> { "Tom", "Jack", "Lucy" };
			Func<string, bool> predicate = (name) => name.Length == 3;
			Func<string, bool> predicate1 = new Func<string, bool>(
				(name) =>
				{
					return true;
				}
			);

			Console.WriteLine("长度为3的名子个数为：" + names.Count(predicate));
			Console.WriteLine("长度为3的名子第1个是：" + names.First(predicate));
		}

		private void test2()
		{
			Action<string> fun = s => Console.WriteLine(s);
			Action<string> f1 = Show;
			Predicate<string> f2 = IsNull;

			f1.Invoke("f1.Invoke(s)");
			f1("f1(s)");
			Process(f1, "pass");

			Console.WriteLine("f2(null) = " + f2(null));
		}
		public void Process(Action<string> act, string arg)
		{
			Console.Write($"public void Process(Action<string> act, string arg) => act(arg): ");
			act(arg);
		}



		public void Show(string s)
		{
			Console.WriteLine(s);
		}

		public bool IsNull(string s)
		{
			return s == null;
		}
	}
}
